package com.itlong.cloud.controller.value;

import com.itlong.cloud.POJO.VO.MessageVO;
import com.itlong.cloud.annotation.AuthAccessRequired;
import com.itlong.cloud.enumerate.ecode.BaseErrorCodeEnum;
import com.itlong.cloud.project.property.IPropertyValueDataAnalyseServiceClient;
import com.itlong.cloud.thrown.DataAccessException;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.context.request.RequestContextHolder;
import org.springframework.web.context.request.ServletRequestAttributes;

import javax.servlet.http.HttpServletRequest;

/**
 * <desc>
 *      物业-物业增值-数据分析控制器
 * </desc>
 *
 * @createDate 2019/06/03
 */
@RestController
@RequestMapping("/propertyValue/colectionRate")
public class PropertyValueDataAnalyseController {

    @Autowired
    IPropertyValueDataAnalyseServiceClient iPropertyValueDataAnalyseServiceClient;


    /**
     * <desc>
     *      获取列表
     * </desc>
     *
     * @param projectId
     * @param year
     * @return
     * @throws Exception
     * @author Jiaqi.X
     * @createDate 2019/06/03
     */
    @ResponseBody
    @AuthAccessRequired
    @PostMapping(path = "list")
    public Object list(String projectId,String year) throws Exception {
        try {
            HttpServletRequest request = ((ServletRequestAttributes) RequestContextHolder.getRequestAttributes()).getRequest();
            projectId = request.getAttribute("projectId") == null ? null : request.getAttribute("projectId").toString();
            year = request.getAttribute("year") == null ? "" : request.getAttribute("year").toString();
            return new MessageVO(BaseErrorCodeEnum.SUCCESS.getErrorCode(), iPropertyValueDataAnalyseServiceClient.getList(projectId,year));
        } catch (Exception e) {
            throw new DataAccessException("【物业_物业增值_数据分析】列表查询失败", e);
        }
    }
}